package beike;

public class Main3 {

    public static void main(String[] args) {
        System.out.println(section2(new int[]{2, 3, 4}, 6));
    }

    public static long section (int[] a, int t) {
        // write code here
        int len = a.length;
        long count = 0;
        boolean[][] dp = new boolean[len][len];
        for (int i = len - 2; i >= 0; i--){
            for (int j = i + 1; j < len; j++){
                if (j - i == 1){
                    if ((a[i]^a[j]) != t){
                        dp[i][j] = true;
                    }
                } else {
                    if ((a[i]^a[j]) != t){
                        dp[i][j] = dp[i+1][j]&&dp[i][j-1];
                    }
                }
            }
        }
        for (int i = 0; i < len; i++){
            for (int j = i + 1; j < len; j++){
                if (dp[i][j]){
                    count++;
                }
            }
        }
        return count;
    }

    public static long section2 (int[] a, int t) {
        // write code here
        int len = a.length;
        long count = 0;
        boolean[] dp = new boolean[len];
        for (int i = len - 2; i >= 0; i--){
            for (int j = i + 1; j < len; j++){
                if (j - i == 1){
                    if ((a[i]^a[j]) != t){
                        dp[j] = true;
                        count++;
                    }
                } else {
                    if ((a[i]^a[j]) != t){
                        dp[j] = dp[j]&&dp[j-1];
                        if (dp[j]){
                            count++;
                        }
                    }
                }
            }
        }
        return count;
    }
}
